package com.clouddot.baipai.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RatingBar;
import android.widget.TextView;

import com.clouddot.baipai.R;
import com.clouddot.baipai.http.entity.response.getEvaluateByDayResponse;
import com.clouddot.baipai.http.entity.response.getEvaluateByWeekResponse;

import java.util.ArrayList;

/**
 * Created by wxy on 2018/8/26.
 */

public class H_FWeekEvaluateAdapter extends RecyclerView.Adapter<H_FWeekEvaluateAdapter.MyViewHolder> {
    private Context mContext;
    private ArrayList<getEvaluateByWeekResponse> mDataList;

    public H_FWeekEvaluateAdapter(Context context, ArrayList<getEvaluateByWeekResponse> dataList) {
        this.mContext = context;
        this.mDataList = dataList;
}

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holder = new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.h_adapter_evaluate_heart_item, parent, false));
        return holder;

        }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        final getEvaluateByWeekResponse bean = mDataList.get(position);
        if (null == bean) {
        return;
        }
        holder.name.setText(bean.ObjectName);
        holder.rb_normal.setIsIndicator(true);
        holder.rb_normal.setRating(Float.parseFloat(bean.SetValue));
        holder.Fraction.setText(bean.SetValue + "");
//        holder.rb_normal.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
//            @Override
//            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
//                listener.onClicked(bean.Id,rating);
//            }
//        });

    }

    @Override
    public int getItemCount() {
        if (mDataList.size() > 0) {
            return mDataList.size();
        }
        return 0;
    }


    class MyViewHolder extends RecyclerView.ViewHolder {
        private final TextView name;
        private final TextView remark;
        private final TextView Fraction;
        private final RatingBar rb_normal;
        public MyViewHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.title);
            remark = itemView.findViewById(R.id.remark);
            rb_normal = itemView.findViewById(R.id.rb_normal);
            Fraction = itemView.findViewById(R.id.Fraction);
        }
    }
    private AdapterItemClickListener listener;

    public void setOnClickListener(AdapterItemClickListener listener) {
        this.listener = listener;
    }

    public interface AdapterItemClickListener {
        void onClicked(String ObjectId, float position);
    }


}
